# -*- coding: utf-8 -*-

# 独立的登录窗口界面
# 从 main_ui_modern.py 中提取的登录相关功能

from PyQt5 import QtCore, QtGui, QtWidgets


class Ui_LoginGUI(object):
    def setupUi(self, LoginGUI):
        LoginGUI.setObjectName("LoginGUI")
        LoginGUI.resize(1200, 1000)
        
       
        # 确保窗口没有额外的装饰
        LoginGUI.setWindowFlags(QtCore.Qt.Window)
        
        # 设置窗口样式 - 更现代的渐变背景
        LoginGUI.setStyleSheet("""
            QWidget {
                background: qlineargradient(x1: 0, y1: 0, x2: 1, y2: 1, 
                    stop: 0 #4facfe, stop: 0.5 #667eea, stop: 1 #764ba2);
                font-family: 'Microsoft YaHei', sans-serif;
                border: none;
                margin: 0px;
                padding: 0px;
            }
            QWidget#LoginGUI {
                background: qlineargradient(x1: 0, y1: 0, x2: 1, y2: 1, 
                    stop: 0 #4facfe, stop: 0.5 #667eea, stop: 1 #764ba2);
            }
        """)
        
        # 主布局
        self.centralWidget = QtWidgets.QWidget(LoginGUI)
        self.centralWidget.setObjectName("centralWidget")
        self.centralWidget.setStyleSheet("""
            QWidget#centralWidget {
                background: transparent;
            }
        """)
        
        self.mainVerticalLayout = QtWidgets.QVBoxLayout(self.centralWidget)
        self.mainVerticalLayout.setContentsMargins(50, 80, 50, 50)
        self.mainVerticalLayout.setSpacing(40)
        self.mainVerticalLayout.setObjectName("mainVerticalLayout")
        
        # 顶部区域 - 包含关闭按钮和标题
        self.headerFrame = QtWidgets.QFrame(self.centralWidget)
        self.headerFrame.setFixedHeight(180)
        self.headerFrame.setStyleSheet("""
            QFrame {
                background: transparent;
                border: none;
            }
        """)
        self.headerFrame.setObjectName("headerFrame")
        
        self.headerLayout = QtWidgets.QVBoxLayout(self.headerFrame)
        self.headerLayout.setContentsMargins(30, 20, 30, 20)
        self.headerLayout.setSpacing(15)
        
        # 顶部控制区域（关闭按钮）
        self.topControlFrame = QtWidgets.QFrame()
        self.topControlFrame.setFixedHeight(50)
        self.topControlFrame.setStyleSheet("background: transparent;")
        
        self.topControlLayout = QtWidgets.QHBoxLayout(self.topControlFrame)
        self.topControlLayout.setContentsMargins(0, 10, 10, 0)
        
        # 添加伸缩空间把关闭按钮推到右边
        self.topControlLayout.addStretch()
        
        # 关闭按钮
        self.closeButton = QtWidgets.QPushButton("×")
        self.closeButton.setFixedSize(40, 40)
        self.closeButton.setStyleSheet("""
            QPushButton {
                background-color: rgba(255, 255, 255, 0.2);
                color: white;
                border: none;
                border-radius: 20px;
                font-size: 24px;
                font-weight: bold;
            }
            QPushButton:hover {
                background-color: rgba(255, 0, 0, 0.6);
            }
            QPushButton:pressed {
                background-color: rgba(255, 0, 0, 0.8);
            }
        """)
        self.topControlLayout.addWidget(self.closeButton)
        
        self.headerLayout.addWidget(self.topControlFrame)
        
        # 应用标题
        self.appTitle = QtWidgets.QLabel("智慧树刷课神器")
        self.appTitle.setStyleSheet("""
            QLabel {
                color: #ff4757;
                font-size: 36px;
                font-weight: bold;
                background: transparent;
                text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.3);
            }
        """)
        self.appTitle.setAlignment(QtCore.Qt.AlignCenter)
        self.headerLayout.addWidget(self.appTitle)
        
        # 副标题
        self.appSubtitle = QtWidgets.QLabel("By_Ti - 助力学习，智能高效刷课")
        self.appSubtitle.setStyleSheet("""
            QLabel {
                color: rgba(255, 255, 255, 0.9);
                font-size: 16px;
                font-weight: 400;
                background: transparent;
                text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);
            }
        """)
        self.appSubtitle.setAlignment(QtCore.Qt.AlignCenter)
        self.headerLayout.addWidget(self.appSubtitle)
        
        self.mainVerticalLayout.addWidget(self.headerFrame)
        
        # 登录卡片
        self.loginCard = QtWidgets.QFrame(self.centralWidget)
        self.loginCard.setMaximumWidth(550)
        self.loginCard.setMinimumWidth(500)
        self.loginCard.setStyleSheet("""
            QFrame {
                background-color: rgba(255, 255, 255, 0.98);
                border-radius: 25px;
                border: 1px solid rgba(255, 255, 255, 0.2);
                box-shadow: 0 20px 40px rgba(0, 0, 0, 0.15);
                backdrop-filter: blur(15px);
            }
        """)
        self.loginCard.setFrameShape(QtWidgets.QFrame.StyledPanel)
        
        # 居中登录卡片
        cardLayout = QtWidgets.QHBoxLayout()
        cardLayout.addStretch()
        cardLayout.addWidget(self.loginCard)
        cardLayout.addStretch()
        
        # 登录卡片内容
        self.loginCardLayout = QtWidgets.QVBoxLayout(self.loginCard)
        self.loginCardLayout.setContentsMargins(50, 50, 50, 50)
        self.loginCardLayout.setSpacing(35)
        
        # 登录标题
        self.loginTitle = QtWidgets.QLabel("用户登录")
        self.loginTitle.setStyleSheet("""
            QLabel {
                font-size: 28px;
                font-weight: bold;
                color: #333;
                margin-bottom: 15px;
                border: none;
                background: transparent;
            }
        """)
        self.loginTitle.setAlignment(QtCore.Qt.AlignCenter)
        self.loginCardLayout.addWidget(self.loginTitle)
        
        # 登录方法选择器
        self.loginMethodWidget = QtWidgets.QTabWidget()
        self.loginMethodWidget.setStyleSheet("""
            QTabWidget::pane {
                border: none;
                background-color: transparent;
                margin-top: 5px;
            }
            QTabBar::tab {
                background: #f0f0f0;
                color: #666;
                padding: 12px 20px;
                margin-right: 4px;
                border-radius: 8px;
                font-size: 14px;
                font-weight: 600;
                min-width: 80px;
            }
            QTabBar::tab:selected {
                background: #667eea;
                color: white;
            }
            QTabBar::tab:hover {
                background: #ddd;
            }
        """)
        
        # 密码登录页面
        self.passwordLoginWidget = QtWidgets.QWidget()
        self.setupPasswordLogin()
        self.loginMethodWidget.addTab(self.passwordLoginWidget, "密码登录")
        
        # 二维码登录页面
        self.qrLoginWidget = QtWidgets.QWidget()
        self.setupQRLogin()
        self.loginMethodWidget.addTab(self.qrLoginWidget, "扫码登录")
        
        self.loginCardLayout.addWidget(self.loginMethodWidget)
        
        self.mainVerticalLayout.addLayout(cardLayout)
        
        # 增加一些间距
        self.mainVerticalLayout.addSpacing(20)
        
        # 免责声明
        self.disclaimerFrame = QtWidgets.QFrame()
        self.disclaimerFrame.setMaximumWidth(650)
        self.disclaimerFrame.setStyleSheet("""
            QFrame {
                background: rgba(255, 255, 255, 0.15);
                border-radius: 15px;
                border: 2px solid rgba(255, 255, 255, 0.3);
                backdrop-filter: blur(10px);
                box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
            }
        """)
        
        disclaimerLayout = QtWidgets.QVBoxLayout(self.disclaimerFrame)
        disclaimerLayout.setContentsMargins(25, 25, 25, 25)
        disclaimerLayout.setSpacing(15)
        
        # 免责声明标题
        self.disclaimerTitle = QtWidgets.QLabel("⚠️ 免责声明")
        self.disclaimerTitle.setStyleSheet("""
            QLabel {
                color: red;
                font-size: 25px;
                font-weight: bold;
                background: transparent;
                border: none;
                margin-bottom: 5px;
                text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);
            }
        """)
        self.disclaimerTitle.setAlignment(QtCore.Qt.AlignCenter)
        disclaimerLayout.addWidget(self.disclaimerTitle)
        
        # 免责声明内容
        self.disclaimerLabel = QtWidgets.QLabel()
        self.disclaimerLabel.setWordWrap(True)
        self.disclaimerLabel.setStyleSheet("""
            QLabel {
                color: rgba(255, 255, 255, 0.9);
                font-size: 20px;
                line-height: 1.6;
                background: transparent;
                border: none;
                padding: 10px 0px;
                text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.3);
            }
        """)
        self.disclaimerLabel.setText(
            "1、本软件仅供用于学习和交流，开发者不对软件的安全性、稳定性、准确性、完整性及适用性作出任何明示或暗示的保证。\n\n"
            "2、因使用本软件而可能导致的任何直接或间接损失，开发者均不承担赔偿责任。\n\n"
            "3、若因本软件与其他软件、硬件设备、操作系统或网络环境存在兼容性问题而引发任何故障，开发者不承担任何责任。"
        )
        disclaimerLayout.addWidget(self.disclaimerLabel)
        
        # 居中免责声明
        disclaimerCenterLayout = QtWidgets.QHBoxLayout()
        disclaimerCenterLayout.addStretch()
        disclaimerCenterLayout.addWidget(self.disclaimerFrame)
        disclaimerCenterLayout.addStretch()
        self.mainVerticalLayout.addLayout(disclaimerCenterLayout)
        
        self.mainVerticalLayout.addStretch()
        
        # 设置主布局
        LoginGUI.setLayout(self.mainVerticalLayout)
        
        self.retranslateUi(LoginGUI)
        QtCore.QMetaObject.connectSlotsByName(LoginGUI)

    def setupPasswordLogin(self):
        """设置密码登录页面"""
        layout = QtWidgets.QVBoxLayout(self.passwordLoginWidget)
        layout.setContentsMargins(0, 30, 0, 30)
        layout.setSpacing(25)
        
        # 账号标签
        self.accountLabel = QtWidgets.QLabel("账号")
        self.accountLabel.setStyleSheet("""
            QLabel {
                color: #374151;
                font-size: 16px;
                font-weight: 600;
                background: transparent;
                margin-bottom: 8px;
                border: none;
            }
        """)
        layout.addWidget(self.accountLabel)
        
        # 用户名输入框
        self.usernameFrame = QtWidgets.QFrame()
        self.usernameFrame.setStyleSheet("""
            QFrame {
                background-color: #ffffff;
                border: 2px solid #e5e7eb;
                border-radius: 10px;
                padding: 2px;
            }
            QFrame:focus-within {
                border-color: #667eea;
                box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
            }
        """)
        
        usernameLayout = QtWidgets.QHBoxLayout(self.usernameFrame)
        usernameLayout.setContentsMargins(16, 12, 16, 12)
        usernameLayout.setSpacing(12)
        
        # 用户图标
        self.userIcon = QtWidgets.QLabel("👤")
        self.userIcon.setStyleSheet("""
            QLabel {
                color: #9ca3af;
                font-size: 20px;
                background: transparent;
            }
        """)
        usernameLayout.addWidget(self.userIcon)
        
        self.Username_Input = QtWidgets.QLineEdit()
        self.Username_Input.setStyleSheet("""
            QLineEdit {
                border: none;
                background: transparent;
                font-size: 16px;
                color: #374151;
                padding: 4px 0px;
                selection-background-color: #667eea;
            }
            QLineEdit::placeholder {
                color: #9ca3af;
            }
        """)
        self.Username_Input.setPlaceholderText("请输入账号")
        usernameLayout.addWidget(self.Username_Input)
        
        layout.addWidget(self.usernameFrame)
        
        # 密码标签
        self.passwordLabel = QtWidgets.QLabel("密码")
        self.passwordLabel.setStyleSheet("""
            QLabel {
                color: #374151;
                font-size: 16px;
                font-weight: 600;
                background: transparent;
                margin-bottom: 8px;
                margin-top: 8px;
                border: none;
            }
        """)
        layout.addWidget(self.passwordLabel)
        
        # 密码输入框
        self.passwordFrame = QtWidgets.QFrame()
        self.passwordFrame.setStyleSheet("""
            QFrame {
                background-color: #ffffff;
                border: 2px solid #e5e7eb;
                border-radius: 10px;
                padding: 2px;
            }
            QFrame:focus-within {
                border-color: #667eea;
                box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.1);
            }
        """)
        
        passwordLayout = QtWidgets.QHBoxLayout(self.passwordFrame)
        passwordLayout.setContentsMargins(16, 12, 16, 12)
        passwordLayout.setSpacing(12)
        
        # 锁图标
        self.lockIcon = QtWidgets.QLabel("🔒")
        self.lockIcon.setStyleSheet("""
            QLabel {
                color: #9ca3af;
                font-size: 20px;
                background: transparent;
            }
        """)
        passwordLayout.addWidget(self.lockIcon)
        
        self.Password_Input = QtWidgets.QLineEdit()
        self.Password_Input.setStyleSheet("""
            QLineEdit {
                border: none;
                background: transparent;
                font-size: 16px;
                color: #374151;
                padding: 4px 0px;
                selection-background-color: #667eea;
            }
            QLineEdit::placeholder {
                color: #9ca3af;
            }
        """)
        self.Password_Input.setEchoMode(QtWidgets.QLineEdit.Password)
        self.Password_Input.setPlaceholderText("请输入密码")
        passwordLayout.addWidget(self.Password_Input)
        
        # 眼睛图标（密码可见性切换）
        self.eyeIcon = QtWidgets.QLabel("👁")
        self.eyeIcon.setStyleSheet("""
            QLabel {
                color: #9ca3af;
                font-size: 20px;
                background: transparent;
                padding: 4px;
                border-radius: 4px;
            }
            QLabel:hover {
                color: #6b7280;
                background-color: #f3f4f6;
            }
        """)
        self.eyeIcon.setCursor(QtCore.Qt.PointingHandCursor)
        passwordLayout.addWidget(self.eyeIcon)
        
        layout.addWidget(self.passwordFrame)
        
        # 间距
        layout.addSpacing(20)
        
        # 登录按钮
        self.login_Button = QtWidgets.QPushButton("登录")
        self.login_Button.setStyleSheet("""
            QPushButton {
                background: qlineargradient(x1: 0, y1: 0, x2: 1, y2: 0, 
                    stop: 0 #ff6b6b, stop: 1 #ee5a24);
                color: white;
                border: none;
                border-radius: 10px;
                padding: 16px 24px;
                font-size: 16px;
                font-weight: 600;
                min-height: 20px;
            }
             QPushButton:hover {
                 background: qlineargradient(x1: 0, y1: 0, x2: 1, y2: 0, 
                     stop: 0 #ff5252, stop: 1 #d63031);
             }
            QPushButton:pressed {
                background: qlineargradient(x1: 0, y1: 0, x2: 1, y2: 0, 
                    stop: 0 #e55039, stop: 1 #b53471);
            }
            QPushButton:disabled {
                background-color: #e5e7eb;
                color: #9ca3af;
            }
        """)
        layout.addWidget(self.login_Button)
        
        # 添加密码可见性切换功能
        self.password_visible = False
        self.eyeIcon.mousePressEvent = self.toggle_password_visibility
    
    def toggle_password_visibility(self, event):
        """切换密码可见性"""
        if self.password_visible:
            self.Password_Input.setEchoMode(QtWidgets.QLineEdit.Password)
            self.eyeIcon.setText("👁")
            self.password_visible = False
        else:
            self.Password_Input.setEchoMode(QtWidgets.QLineEdit.Normal)
            self.eyeIcon.setText("🙈")
            self.password_visible = True

    def setupQRLogin(self):
        """设置二维码登录页面"""
        layout = QtWidgets.QVBoxLayout(self.qrLoginWidget)
        layout.setContentsMargins(0, 30, 0, 30)
        layout.setSpacing(25)
        
        # 二维码显示区域
        self.qrCodeFrame = QtWidgets.QFrame()
        self.qrCodeFrame.setFixedSize(220, 220)
        self.qrCodeFrame.setStyleSheet("""
            QFrame {
                background-color: #f8f9fa;
                border: 3px dashed #dee2e6;
                border-radius: 15px;
            }
        """)
        
        qrLayout = QtWidgets.QVBoxLayout(self.qrCodeFrame)
        self.qrcode_img_label = QtWidgets.QLabel()
        self.qrcode_img_label.setAlignment(QtCore.Qt.AlignCenter)
        self.qrcode_img_label.setText("二维码加载中...")
        self.qrcode_img_label.setStyleSheet("QLabel { color: #6c757d; font-size: 16px; }")
        qrLayout.addWidget(self.qrcode_img_label)
        
        # 居中二维码
        qrCenterLayout = QtWidgets.QHBoxLayout()
        qrCenterLayout.addStretch()
        qrCenterLayout.addWidget(self.qrCodeFrame)
        qrCenterLayout.addStretch()
        layout.addLayout(qrCenterLayout)
        
        # 二维码信息
        self.QRCodeInfo_label = QtWidgets.QLabel("请使用APP扫码登录")
        self.QRCodeInfo_label.setStyleSheet("""
            QLabel {
                color: #fff;
                font-size: 14px;
                background: transparent;
            }
        """)
        self.QRCodeInfo_label.setAlignment(QtCore.Qt.AlignCenter)
        layout.addWidget(self.QRCodeInfo_label)
        
        # 刷新按钮
        self.refreshQRCode_Button = QtWidgets.QPushButton("刷新二维码")
        self.refreshQRCode_Button.setStyleSheet("""
            QPushButton {
                background: qlineargradient(x1: 0, y1: 0, x2: 1, y2: 0, 
                    stop: 0 #ff6b6b, stop: 1 #ee5a24);
                color: white;
                border: none;
                border-radius: 8px;
                padding: 12px 20px;
                font-size: 14px;
                font-weight: 600;
            }
             QPushButton:hover {
                 background: qlineargradient(x1: 0, y1: 0, x2: 1, y2: 0, 
                     stop: 0 #ff5252, stop: 1 #d63031);
             }
            QPushButton:pressed {
                background: qlineargradient(x1: 0, y1: 0, x2: 1, y2: 0, 
                    stop: 0 #e55039, stop: 1 #b53471);
            }
        """)
        layout.addWidget(self.refreshQRCode_Button)

    def retranslateUi(self, LoginGUI):
        _translate = QtCore.QCoreApplication.translate
        LoginGUI.setWindowTitle(_translate("LoginGUI", "智慧树刷课神器 - 登录"))
